var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        infoContent: [],
        copyright: '',
        catName:'',
        currentNum:0,
        blist: {},
        tcolor: '',
        contact_name_size: 22,
        hide_tabbar: '0',
        markers: [{
            iconPath: "../../resource/images/mark1.png",
            id: 0,
            latitude: 22.540430,
            longitude: 113.934540,
            width: 40,
            height: 40
        }]

    },
    onShow:function(){
        app.globalSeo('obut').then(res =>{
            // console.log(res);
            this.setData({
                'catName':res.seo_title
            })
            swan.setPageInfo({

                    title: res.seo_title,
                    keywords: res.seo_keywords,
                    description: res.seo_description,
                    articleTitle: res.seo_articleTitle,
                    image:  res.seo_img,
                    // releaseDate: '2019-01-02 12:01:30',
                })
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {

        var that = this
        var uniacid = app.siteInfo.uniacid;
        let pages = getCurrentPages();
        
        var url = '/' + pages[pages.length -1].uri;
        var sysinfo = swan.getStorageSync('info');
        app.head_backgroup(sysinfo);
        if (sysinfo == '') {
            app.globalSetting().then(res => {
                for (let index in res.nav) {
                    var item = res.nav[index];

                    if (item.url == url) {
                        app.globalData.currentNum = index;
                        break;
                    }

                }
                this.setData({
                    'info': res,
                    'currentNum': app.globalData.currentNum
                });
            });
        } else {
            for (let index in sysinfo.nav) {
                var item = sysinfo.nav[index];
                if (item.url == url) {
                    app.globalData.currentNum = index;
                    break;
                }
            }
            this.setData({
                'info': sysinfo,
                'currentNum': app.globalData.currentNum
            });
        }
        // this.setData({
        //   copyright: app.globalData.copyright
        // })
        // that.setTabBar()
        swan.request({
            url: app.util.url('entry/baiduapp/Contact'),
            method: 'GET',
            dataType: 'json',
            data: {
                uniacid: app.siteInfo.uniacid,
                m: app.siteInfo.mName,
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            success: function (res) {
                if (!res.data.errno) {
                    // console.log(res.data);
                    var name = res.data.data.name;

                    res.data.data.size = 22;

                    if (name.length > 10) {
                        res.data.data.size = 16;
                    }
                    if (name.length > 14) {
                        res.data.data.size = 14;
                    }
                    if (name.length > 16) {
                        res.data.data.size = 12;
                    }
                    //   var markers = that.data.markers
                    //   markers[0].latitude = res.data.data.jing
                    //   markers[0].longitude = res.data.data.wei
                    //   console.log(res.data.data);
                    that.setData({
                        infoContent: res.data.data,
                        // markers: markers
                    })
                    swan.setNavigationBarTitle({
                        title: '联系我们',
                    })




                }
            }
        });

    },
    isEmptyObject: function (obj) {
        for (var key in obj) {
            return false;
        }
        return true;
    },
    onShareAppMessage: function (res) {
        return {
            title: this.data.catName,
            path: '/pages/contact/contact'
        }
    },
    baiduShare: function () {
        swan.openShare({
            title: this.data.catname,
            content: '1',
            path: '/pages/contact/contact'
        });
    },

    saveAddressListAction: function () {
        swan.addPhoneContact({
            firstName: this.data.info.contact_username,
            mobilePhoneNumber: this.data.info.phone,
            organization: this.data.info.contact_name
        })
    },
    tels: function (){
        var phone = this.data.infoContent.phone;
        app.tel(phone);
    },
    tel(e) {

        app.tel(e.currentTarget.dataset.val);
    },
    http_tab(e) {

        app.tabNav(e);
    },
    http_navigator(e) {
        app.tonav(e);
    },
    copy_action: function () {
        var copy = this.data.blist.copyright
        if (copy.copy_kind == '1') {
            var phone = copy.copy_phone
            swan.makePhoneCall({
                phoneNumber: phone,
            })
        }
        if (copy.copy_kind == '2') {
            var appid = copy.copy_appid;
            var pageaddress = copy.copy_ddress;
            swan.navigateToSmartProgram({
                appKey: appid,
                path: pageaddress,
                success(res) {
                }
            })

        }
    },

    copy_content: function (e) {
        let id = e.currentTarget.dataset.id;
        var data_content;
        console.log('11_' + id);
        switch (id) {
            case 'email':
                data_content = this.data.info.email;
                break;
            case 'qq':
                data_content = this.data.info.qq;
                break;
            case 'address':
                data_content = this.data.info.address;
                break;
        }



        swan.setClipboardData({
            data: data_content,
            success: res => {
                swan.showToast({
                    title: '复制成功'
                });
            },
            fail: err => {
                swan.showToast({
                    title: '复制失败'
                });
                console.log('setClipboardData fail', err);
            }
        });



    }

})